package com.example.demo.config.artemis;

import org.apache.activemq.artemis.api.core.client.ClientProducer;
import org.apache.activemq.artemis.api.core.client.ClientSession;

import java.util.Date;

/**
 * @author Rocket
 * @version 10.0.1
 * @date 2021-10-22 9:41 PM
 */
public class ProducerTest {
    public static void main(String[] args) throws InterruptedException {
        ActiveMqManager.initClientSessionFactory();
        for(int j = 0; j < 5; j++) {
            Thread.sleep(10);
            final ClientSession session = ActiveMqManager.createClientSession(ActiveMqManager.PROTO_TCP, Boolean.TRUE);

            //ActiveMqManager.createQueue(session, ActiveMqManager.RDO_QUEUE_TCP + j);
            ClientProducer producer = ActiveMqManager.createNewProducer(session, ActiveMqManager.RDO_QUEUE_TCP+ j);
            new Thread(()-> {
                for(int i = 0; i < 10000; i++) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                    }
                    ActiveMqManager.sendMessage(session, producer,Thread.currentThread().getName()  + "-" + i + ":" + new Date(), true);
                }

                //ActiveMqManager.closeSession(session);
            }, "PRODUCER-" + j).start();

        }
    }
}
